<?php
class Application_Form_Empreses extends Zend_Form
{

    public function init()
    {
        $this->setAttrib('id', 'frmEmpreses')        	 
        	 ->setEnctype('multipart/form-data')
        	 ->setMethod('post');
       	
       	$this->addElement('hidden', 'id_empresa', array('label' =>'Id Empresa'));
       	
       	$this->addElement('text', 'titulo', array(
       	'label' 	=> 'Nom empresa',
       	'filters'   => array('StringTrim'),
       	'required'  => true,
    	'size'		=> 60,
       	'validators'=> array(
                array('validator' => 'StringLength', 'options' => array(3, 50))
                )
       	));
       	$this->addElement('textarea', 'texto', array(
       	'label' 	=> 'Descripció activitat',
       	'filters'   => array('StringTrim'),
    	'size'		=> 60,
       	'cols'   	=> 44,
       	'rows'   	=> 5,
       	'validators'=> array(
                array('validator' => 'StringLength', 'options' => array(3, 256))
                )
       	));
       	
       	$element = new Zend_Form_Element_File('file');
       	
		$element->setLabel('Upload an image:');
		
		// ensure only 1 file
		$element->addValidator('Count', false, 1);
		
		// limit to 100K
		$element->addValidator('Size', false, 102400);
		
		$element->addDecorator('ViewHelper');
		
		// only JPEG, PNG, and GIFs
		$element->addValidator('Extension', false, 'jpg,png,gif');
		$this->addElement($element, 'file');
        
       	$this->addElement('hidden', 'imagen');
       	
       	$this->addElement('text', 'direccion', array(
       	'label' 	=> 'Adreça',
       	'filters'   => array('StringTrim'),
    	'size'		=> 60,
       	'validators'=> array(
                array('validator' => 'StringLength', 'options' => array(3, 150))
                )
       	));
       	
       	$this->addElement('hidden', 'actividad', array(
       	'label' => 'Activitat',
       	'required' => true		
       	));
       	
       	$this->addElement('text', 'cp', array(
       	'label' 	=> 'Codi postal',
       	'filters'   => array('StringTrim'),
    	'size'		=> 60,
       	'validators'=> array(
                array('validator' => 'StringLength', 'options' => array(5, 8))
                )
       	));
       	
       	$this->addElement('text', 'localidad', array(
       	'label' 	=> 'Localitat',
       	'filters'   => array('StringTrim'),
    	'size'		=> 60,
       	'validators'=> array(
                array('validator' => 'StringLength', 'options' => array(3, 150))
                )
       	));
       	
       	$this->addElement('text', 'telefono', array(
       	'label' 	=> 'Telèfon',
       	'filters'   => array('StringTrim'),
    	'size'		=> 60,
       	'validators'=> array(
                array('validator' => 'StringLength', 'options' => array(3, 15))
                )
       	));
       	
       	$this->addElement('text', 'fax', array(
       	'label' 	=> 'Fax',
       	'filters'   => array('StringTrim'),
    	'size'		=> 60,
       	'validators'=> array(
                array('validator' => 'StringLength', 'options' => array(3, 15))
                )
       	));
       	
       	$this->addElement('text', 'email', array(
       	'label' 	=> 'E-Mail',
       	'filters'   => array('StringTrim'),
    	'size'		=> 60,
       	'validators'=> array(
       						 array('validator' => 'StringLength', 'options' => array(3, 50)),
       						 array('validator' => 'EmailAddress')
       						 )
       	));
       	
       	$this->addElement('submit', 'submit', array('label' => 'Guardar y tancar'));
    }
    
    public function showErrors($arrMessages)
    {   
    	$valores = '';
	    foreach ($arrMessages as $key => $value) {
    		foreach ($arrMessages[$key] as $value2) {
    			$label = $this->getElement($key)->getLabel();
    			$valores.= "<li>El camp $label no es correcte. Error:$value2</li>";	
    		}
    	}
    	//print_r($valores);
		return "<ul>".$valores."</ul>";
    }
}

